import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class MyMapper extends Mapper<Object, Text, Text, LongWritable> {
    private final Text keyOut = new Text();
    private final LongWritable valueOut = new LongWritable();

    /**
     * 输入：一堆文件
     * 输出：word;filename 1
     */
    @Override
    protected void map(Object key, Text value, Mapper<Object, Text, Text, LongWritable>.Context context) throws IOException, InterruptedException {
        String[] words = value.toString().split(" ");
        int lnNum = Integer.parseInt(words[0]);
        String filename = lnNum / 10 + ".txt";
        for (int i = 1; i < words.length; i++) {
            keyOut.set(words[i] + ";" + filename);
            valueOut.set(1L);
            context.write(keyOut, valueOut);
        }
    }
}
